home *** CD-ROM | disk | FTP | other *** search
- <![CDATA[
- // CTopicInfo: Object consolidating topic info of the topic currently
- // being processed. Encapsulates topic info like Standards info,
- // Ansi/Unicode info, etc. //at
-
- // Here are some display text strings that are used.
- var sThis = "This ";
- var sAnd = " and ";
- var sDef = "is defined in ";
- var sDep = "is deprecated in ";
- var sPro = "is part of a proposed addition to ";
- var sMSE = "is a Microsoft extension to ";
- var sNMS = "is an extension to ";
-
- // Augment string object with a trim method.
- String.prototype.trimsp = function()
- {
- return this.replace(/(^\s+)|(\s+$)/g, "");
- }
-
- function CTopicInfo()
- {
- this._bInitialized = false;
- }
-
- CTopicInfo.prototype.Init = function()
- {
- if (this._bInitialized)
- return false;
-
- this._oTopic = null;
- this._nStds = 0;
- this._aStds = null;
- this._oCurStd = null;
- this._oAc = null;
- this._sTLA = "";
- this._sRID = "";
- this._sXRID = "";
- this._sTypeName = "";
- this._sTypeCaption = "";
- this._sError = "";
-
- this._bInitialized = true;
-
- return true;
- }
-
- CTopicInfo.prototype.ResetInit = function()
- {
- this._bInitialized = false;
- }
-
- CTopicInfo.prototype.SetErrorAndFail = function(sErr)
- {
- this._sError = sErr;
- this.ResetInit();
- return false;
- }
-
- CTopicInfo.prototype.BadTLA = function()
- {
- var bError = false;
-
- if (this._sError == "badtla")
- bError = true;
-
- return bError;
- }
-
- CTopicInfo.prototype.BadStd = function()
- {
- var bError = false;
-
- if (this._sError == "badstd")
- bError = true;
-
- return bError;
- }
-
- CTopicInfo.prototype.BadLogic = function()
- {
- var bError = false;
-
- if (this._sError == "badlogic")
- bError = true;
-
- return bError;
- }
-
- CTopicInfo.prototype.BadXRef = function()
- {
- var bError = false;
-
- if (this._sError == "badxref")
- bError = true;
-
- return bError;
- }
-
- // Return true if there was an error.
- CTopicInfo.prototype.WasError = function()
- {
- var bError = false;
-
- if (this._sError != "")
- bError = true;
-
- return bError;
- }
-
- // See if the current page's id is listed in standards.xml. //at
- // Perform some initial one-time setup if it is.
- CTopicInfo.prototype.HasInfo = function(oTopicData)
- {
- var bFound = false;
- var sID = oTopicData._sID;
- var aStds = null;
- var oDoc = goCtx.GetDocument();
- var oMeta = null;
- var sMetaType = "";
- var sPType = this._sTypeName;
-
- if (!sPType && oDoc)
- {
- sPType = "";
- oMeta = oDoc.selectSingleNode("/inetsdk:topic/metadata");
- if (oMeta)
- {
- sMetaType = oMeta.getAttribute("type");
- if (sMetaType)
- {
- //this is a total hack to handle the one doctype.xml page - petertay
- if (sMetaType=="htmldeclaration")
- {
- sPType = "declaration";
- }
- else
- {
- sPType = sMetaType;
- }
- this._sTypeCaption = sPType;
- this._sTypeName = sPType;
- }
- }
- }
-
- this._sRID = sID;
-
- this._oTopic = goLookup.RetrieveTopicInfo(sID);
- if (this._oTopic)
- {
- // this.ResetInit();
- aStds = this._oTopic.selectNodes("standards/standard");
- this._aStds = aStds;
- if (aStds)
- {
- this._nStds = aStds.length;
- if (this._nStds)
- {
- this._oCurStd = aStds[this._nStds-1];
- bFound = true;
- }
- }
- }
- else
- this._sError = goLookup._error;
-
- return bFound;
- }
-
- // Return true if no standard applies.
- CTopicInfo.prototype.IsNoStd = function()
- {
- var bNoStd = false;
- var oStd = null;
-
- if (this._aStds.length)
- {
- oStd = this._aStds[0];
- if (oStd)
- if (oStd.getAttribute("no_standard"))
- bNoStd = true;
- }
-
- return bNoStd;
- }
-
- // Return current standards countdown.
- CTopicInfo.prototype.NumStds = function()
- {
- return this._nStds;
- }
-
- // Get the literal display text for the current standard node.
- // Check for bad attribute logic.
- CTopicInfo.prototype.GetText = function()
- {
- var sRet = "";
- var sVal = "";
- var sTLA = "";
- var sExt = "";
- var bDep = false;
- var bPro = false;
- var sLit = "";
- var sAtt = "";
- var bAtt = false;
- var bOk = true;
- var oDoc = goCtx.GetDocument();
- var oMeta = null;
- var sMetaType = "";
- var sPType = this._sTypeName;
-
- if (!sPType && oDoc)
- {
- sPType = "";
- oMeta = oDoc.selectSingleNode("/inetsdk:topic/metadata");
- if (oMeta)
- {
- sMetaType = oMeta.getAttribute("type");
- if (sMetaType)
- {
- sPType = sMetaType;
- this._sTypeCaption = sPType;
- this._sTypeName = sPType;
- }
- }
- }
-
- // Got a live standard entry--get the attributes.
- sTLA = this._oCurStd.getAttribute("tla");
- sExt = this._oCurStd.getAttribute("extension");
- if (this._oCurStd.getAttribute("deprecated"))
- bDep = true;
- if (this._oCurStd.getAttribute("proposed"))
- bPro = true;
-
- // Check the attribute logic.
- if (!sTLA)
- bOk = false;
- if (bOk && sExt && (bDep || bPro))
- bOk = false;
- if (bOk && bDep && (sExt || bPro))
- bOk = false;
- if (bOk && bPro && (sExt || bDep))
- bOk = false;
-
- // Now assemble the text string based on the attributes.
- if (bOk)
- {
- this._sTLA = sTLA;
- this._oAc = goLookup.RetrieveAcronym(sTLA);
- if (this._oAc)
- {
- bAtt = (sExt || bDep || bPro);
- sAtt = this._oAc.getAttribute("standard");
- if (sAtt && bAtt && (sAtt == "specific"))
- {
- this._sError = "badlogic";
- bOk = false;
- }
- else
- {
- // Assemble the literal text part of the sentence.
- sLit = sDef;
- if (bDep)
- sLit = sDep;
- else if (bPro)
- sLit = sPro;
- else if (sExt == "ms")
- sLit = sMSE;
- else if (sExt == "nonms")
- sLit = sNMS;
- }
- }
- else
- {
- this._sError = "badtla";
- bOk = false;
- }
- }
- else
- this._sError = "badlogic";
-
- if (bOk)
- {
- if (this._nStds == this._aStds.length)
- sRet = sThis + sPType + " " + sLit;
- else
- sRet = " " + sLit;
- }
-
- return sRet;
- }
-
- // Set the basic type name caption.
- CTopicInfo.prototype.SetTypeName = function(sType, sTypeCaption)
- {
- var oDoc = goCtx.GetDocument();
- var oMeta = null;
- var sMetaType = "";
-
- this.Init();
-
- if (oDoc)
- {
- oMeta = oDoc.selectSingleNode("/inetsdk:topic/metadata");
- if (oMeta)
- {
- sMetaType = oMeta.getAttribute("type");
- if (sMetaType == sType)
- {
- this._sTypeCaption = sTypeCaption;
- this._sTypeName = sTypeCaption.toLowerCase();
- }
- }
- }
- }
-
- // Return current page type name. //at
- CTopicInfo.prototype.GetTypeName = function()
- {
- return this._sTypeName;
- }
-
- // Return current page type name. //at
- CTopicInfo.prototype.GetTypeCaption = function()
- {
- return this._sTypeCaption;
- }
-
- // Lookup the href path to the destination.
- CTopicInfo.prototype.GetHREF = function()
- {
- var sRet = "";
- var sErr = "";
- var bOk = false;
- var sXrid = ""; //at
- var sXML = "";
- var oTNode = null;
- var oTDom = goCtx._oTDom;
-
- if (this._oAc)
- {
- sXrid = this._oAc.getAttribute("xrid");
- if (sXrid)
- {
- this._sXRID = sXrid;
- sXML = "<xref rid=\"" + sXrid + "\"></xref>";
-
- // Now use "mini-dom" node to load node-xml and get a node.
- oTDom.async = false;
- oTDom.loadXML(sXML);
- oTNode = oTDom.documentElement;
- if (oTNode)
- {
- if (goLookup.LookupByNode(oTNode, goDest))
- {
- sRet = goDest.GetHREF();
- bOk = true;
- }
- else
- sErr = "badxref";
- }
- else
- sErr = "badxref";
- }
- else
- sErr = "badtla";
- }
- else
- sErr = "badtla";
-
- if (!bOk && !this._sError)
- this._sError = sErr;
-
- return sRet;
- }
-
- // Get the name of the standard from the acronyms entry. //at
- CTopicInfo.prototype.GetName = function()
- {
- //at var sRet = goDest.GetCaption();
- var sRet = goLookup.GetTLA(this._oAc);
-
- if (sRet)
- sRet = sRet.trimsp();
- else
- sRet = "";
-
- return sRet;
- }
-
- // Get the TLA rid/name. //at
- CTopicInfo.prototype.GetTLA = function()
- {
- var sRet = this._sTLA;
-
- return sRet;
- }
-
- // Get appropriate ending for the standard citation sentence.
- CTopicInfo.prototype.GetEnd = function()
- {
- var sRet = ". ";
- var n = this._nStds;
-
- if (n > 2)
- sRet = ", ";
- else if (n == 2)
- {
- if (this._aStds.length > 2)
- sRet = "," + sAnd;
- else
- sRet = sAnd;
- }
- else if (n == 1)
- sRet = ". ";
-
- this._nStds--;
- if (this._nStds > 0)
- this._oCurStd = this._aStds[this._nStds-1];
-
- return sRet;
- }
-
- // Get the xref rid.
- CTopicInfo.prototype.GetXRID = function()
- {
- return this._sXRID;
- }
-
- // Does the HREF require a leave icon?
- CTopicInfo.prototype.IsLeave = function(sLeave)
- {
- var bLeave = false;
-
- if (goDest._leave == sLeave)
- bLeave = true;
-
- return bLeave;
- }
-
-
- // CTopicData: Object encapsulating internal data for of the topic
- // currently being processed. //at
- function CTopicData(oCtx)
- {
- this._oCtx = oCtx;
- this._isValid = false;
- this._error = "";
- }
-
- // last error that occurred while attempting to lookup the current topic
- CTopicData.prototype.GetError = function()
- {
- return this._error;
- }
-
- CTopicData.prototype.IsSelf = function(sID)
- {
- return (this._sID == sID);
- }
-
- // published url to the current topic
- CTopicData.prototype.GetHREF = function()
- {
- return this._oDest.GetHREF();
- }
-
- // caption of the current topic
- CTopicData.prototype.GetCaption = function()
- {
- return this._oDest.GetCaption();
- }
-
- // Given the current topic's id, lookup the current topic in targets
- CTopicData.prototype.Ensure = function()
- {
- if (this._oDest)
- {
- return this._isValid;
- }
-
- this._oDest = new CLookupResults();
-
- var oCtx = this._oCtx;
-
- var oDoc = oCtx.GetDocument();
- if (!oDoc)
- {
- this._error = "document reference unavailable in LookupLocal";
- return false;
- }
-
- var oIDAttr = oDoc.selectSingleNode("/inetsdk:topic/metadata/@id");
- if (!oIDAttr)
- {
- this._error = "Unable to retrieve id from current topic.";
- return false;
- }
-
- this._sID = oIDAttr.value;
-
- // the following call will typically fail if the current topic is not
- // registered in the lookup database.
- if (goLookup.LookupByRID(this._sID, this._oDest, true, oCtx.GetDevLang(), "auto"))
- {
- this._isValid = true;
- return true;
- }
- else if (oCtx.AllowSelfUnregistered() && goLookup.LookupLocal(null, this._oDest))
- {
- this._isValid = true;
- return true;
- }
- else
- {
- this._error = "Current Topic Lookup: " + goLookup.GetError();
- return false;
- }
- }
-
- ]]>
-